<template>
    <div class="address-container">
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media" style="height: 50px;line-height: 35px">

                <a href="javascript:;">
                    <router-link class="mui-text-center" :to="'/user/addaddress/'+id" style="color: #0f0f0f;text-align: center">
                        添加地址
                    </router-link>
                </a>
            </li>
            <li class="mui-table-view-cell mui-transitioning" v-for="item in list" :key="item.id">
                <div class="mui-slider-right mui-disabled">
                    <a class="mui-btn mui-btn-red" style="transform: translate(0px, 0px);" @click.prevent="deleteAddress(item.id)">删除</a>
                    <a class="mui-btn mui-btn-blue" style="transform: translate(0px, 0px);" @click.prevent="editAddress(item.id)">编辑</a>
                </div>
                <div class="mui-slider-handle" style="transform: translate(0px, 0px);">
                    <p><span>邮编:</span><span>{{item.port}}</span><span style="margin-left: 15px">收货人:{{item.per}}</span></p>
                    <p class='mui-ellipsis'>{{item.address}}</p>
                </div>
            </li>

        </ul>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';
    import { MessageBox } from 'mint-ui';
    import mui from '../../lib/dist/js/mui.js'
    export default {
        data(){
            return{
                id:this.$route.params.id,
                list:[],
            }
        },
        created(){
            this.getAddlist();
        },
        mounted(){
            mui.init();
        },
        methods:{
            getAddlist(){
                this.$http.get('http://127.0.0.1:3002/getAddress?id='+this.id).then((result)=>{
                    if(result.body.status === 0){
                        this.list = result.body.message;
                        console.log(this.list);
                    }else{
                        Toast('您的网络抽风了');
                    }
                })
            },
            deleteAddress(id){
                var This = this;
                mui.confirm('您确定删除地址',function (message) {
                    if(message.index === 0){
                        This.$router.push('/user/address/'+This.id);
                    }else{
                        This.$http.get('http://127.0.0.1:3002/deleteAddress?id='+id).then((result)=>{
                            if(result.body.status ===0){
                                Toast(result.body.message);
                                This.$router.push('/user/address/'+This.id);
                            }else {
                                Toast('您的网络抽风了');
                            }
                        })
                    }
                })

            },
            editAddress(id){
                var This = this;
                mui.confirm('您确定修改地址',function (message) {
                    if(message.index === 0){
                        This.$router.push('/user/address/'+This.id);
                    }else {
                        This.$router.push('/user/editaddress/'+id+'/'+This.id);
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>